<?php
function send_apns($req) {
	if(empty($req)) return false;

    $ip = "127.0.0.1";
    $port = "22195";
    $timeout = 30;
    $ret = "";
    if (($fp = fsockopen($ip, $port, $errno, $errstr, $timeout)) == false)
        return "Error $errno: $errstr\n";

    stream_set_timeout($fp, $timeout, 0);
    $res = fwrite($fp, $req, strlen($req));
        echo $res."\n";
    while ($line = fread($fp, 8192)) $ret .= $line;
        echo $ret;
    fclose($fp);
	return $ret;
}
$token = "6cfaa206281fa5ffb69f1800a75fc9a060efa730276b2fb8c9c9bdc19bcc1719";
$apns[0] = array(
    'device_token'=>$token,
    'alert'=>'test啦',
    'badge'=>5,
    'sound'=>'beep.wav',
);

$g = array(
    'key'=>'IqXbB4M6',
    'data'=>$apns
);
$msg = json_encode($g);
//echo $msg;exit;
$res = send_apns($msg);
?>
